<template>
    <video-player class="video-player vjs-custom-skin" id="videoPlayer" ref="videoPlayer"
     :playsinline="true" @play="onPlayerPlay($event)"
      :options="videoOptions"></video-player>
</template>
<script>
// import "videojs-flash";
import "video.js/dist/lang/zh-CN";
// import SWF_URL from 'videojs-swf/dist/video-js.swf';

export default {
    props: ["playParam"],
    data() {
        return {
            videoOptions: {
                loop: false,
                height: "360",
                language: "zh-CN",
                sources: [
                    {
                        type: "application/x-mpegURL",
                        src: "blala"
                    }
                ],
                // flash: {swf: SWF_URL },
                // techOrder: ["flash"],
                autoplay: false,
                controls: true,
                poster: "",
                controlBar: {
                    timeDivider: true,
                    durationDisplay: true,
                    remainingTimeDisplay: false,
                    fullscreenToggle: true //全屏按钮
                }
            }
        };
    },
    mounted() {
        // console.info(this.playParam.play_url);
        this.$refs.videoPlayer.player.src({
            type: "application/x-mpegURL",
            src: this.playParam.play_url
        });
        this.$refs.videoPlayer.player.play();
    },
    methods: {
        onPlayerPlay() {
            var normal_currentTime = this.$refs.videoPlayer.player.currentTime();
            setTimeout(() => {
                var unnormal_currentTime = this.$refs.videoPlayer.player.currentTime();
                if (
                    normal_currentTime.toString() ==
                    unnormal_currentTime.toString()
                ) {
                    this.$refs.videoPlayer.player.pause();
                    this.$refs.videoPlayer.player.play();
                }
            }, 300);
        }
    }
};
</script>